#Include <..\include\Common_For_PageManager.au3>
#Include <GuiListBox.au3>

Dim Const $sFunctionFolderPath = "C:\"&$sSectionAppBar&"\"
Dim Const $SamplePatch = "C:\"&$sSectionAppBar&"\Sample\"
Dim Const $CorrectResutPath = "C:\"&$sSectionAppBar&"\Correct Resut\"
Dim Const $PerformResultPath = "C:\"&$sSectionAppBar&"\Perform Result\"


Dim Const $iNumber = Common_GetNumberInExcelSheet($oExcel,$sAppBarFunctionName)  
Dim Const $iCurrentSheetTotalLineNumber = $iNumber[0]   ;Get all number of rows in current excel sheet.

Dim Const $sExcelSheetName = 'ApplicationBar'
Dim Const $iRescolumn = 15
;App nar define value

Dim Const $nIconCount 		= Number(ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, 'IconCount'))
Dim Const $sConvertTime		= Number(ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, 'ConvertTime'))

;Read info form ini
Dim Const $sApplicationBar					 			= Number(ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, 'ApplicationBar'))
Dim Const $sApplicationPropertiesDialogTitle 			= ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "ApplicationPropertiesDialogTitle")
Dim Const $sAppListBox						 			= Number(ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, 'AppListBox'))
Dim Const $sAppearInAppBarCheckBox			 			= Number(ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, 'AppearInAppBarCheckBox'))
Dim Const $sAcceptMultipleFilesCheckBox			 		= Number(ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, 'AcceptMultipleFilesCheckBox'))
Dim Const $sTransformFormatRadioButton					= Number(ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, 'TransformFormatRadioButton'))
Dim Const $sAutomaticFormatTransformationRadioButton 	= Number(ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, 'AutomaticFormatTransformationRadioButton'))
Dim Const $sKeepOriginalFormatRadioButton				= Number(ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, 'KeepOriginalFormatRadioButton'))
Dim Const $sFormatComboBox								= Number(ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, 'FormatComboBox'))
Dim Const $sRegisterApplicationWizardTtile 				= ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "RegisterApplicationWizardTtile")
Dim Const $sOutLookTitle 								= ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "OutLookTitle")
Dim Const $sConvertInformationTitle 					= ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "ConvertInformationTitle")
Dim Const $sShowLogFileButton							= Number(ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, 'ShowLogFileButton'))
Dim Const $sLogFileClass 								= ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "LogFileClass")
Dim Const $sWordPadClass 								= ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "WordPadClass")
Dim Const $sPrintFunTitle 								= ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "PrintFunTitle")

Dim Const $sMSPaintClass 								= ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "MSPaintClass")
Dim Const $sIEClass 									= ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "IEClass")
Dim Const $sWordClass 									= ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "WordClass")
Dim Const $sExcelClass 									= ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "ExcelClass")
Dim Const $sPPTClass 									= ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "PPTClass")


Dim Const $sPDFwriter  = ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "PDFwriter")
Dim Const $sOutlook    = ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "Outlook")
Dim Const $sWord       = ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "Word")
Dim Const $sExcel      = ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "Excel")
Dim Const $sPowerPoint = ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "PowerPoint")
Dim Const $sWordPad    = ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "WordPad")
Dim Const $sPrintFun   = ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "PrintFun")

Dim Const $sMSPaint    = ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "MSPaint")
Dim Const $sIE	       = ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "IE")


If $sPMVersion = "FE" Then
	Dim Const $sEZPictureClass 							= ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "EZPictureClass")
	Dim Const $sEZPicture  								= ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, "EZPicture")
EndIf


Dim Const $sFileNameEditBoxInSaveAsDlg	  	  		   = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameThumbanil, 'FileNameEditBoxInSaveAsDlg'))
Dim Const $sSaveButtonInSaveAsDlg		  	  		   = ReadIniKeyValue($sPCodeIniPath, $sSectionNameThumbanil, 'SaveButtonInSaveAsDlg')
Dim Const $sDisPlayPrintDialogBeforePrinting_CheckBox  = Number(ReadIniKeyValue($sPCodeIniPath, $sSectionNameFax, 'DisPlayPrintDialogBeforePrinting_CheckBox'))
Dim Const $sPrint_Dialog 		  	  		   		   = ReadIniKeyValue($sPCodeIniPath, $sSectionNameFax, 'Print_Dialog ')




Func InitializeStatusForAppBar()
	
	If ProcessExists("PmCloudShareEvernote.exe") Then
		ProcessClose("PmCloudShareEvernote.exe")
	EndIf
	
	#cs
	Local $IsOfficeOpened = 0
	
	If WinExists("[CLASS:XLMAIN]") Then   ;Excle
		WinActivate("[CLASS:XLMAIN]")
		$IsOfficeOpened = 1
	EndIf	

	If WinExists("[CLASS:PPTFrameClass]") Then   ;PPT
		WinActivate("[CLASS:PPTFrameClass]")
		$IsOfficeOpened = 1
	EndIf
	
	If WinExists("[CLASS:OpusApp]") Then   ;Word
		WinActivate("[CLASS:OpusApp]")
		$IsOfficeOpened = 1
	EndIf
	
	If $IsOfficeOpened = 1 Then
		Sleep(300)
		Send("!f")   ;Open "File" Menu.
		Sleep(500)
		Send("!f")   ;Open "File" Menu. For DOC type, after print, must sent !f twice. Word then can respond.
		Sleep(1000)
		Send("x")   ;Exit 
		Sleep(1000)
		
		;Don't save for save or not dialog.
		If WinExists("[CLASS:NUIDialog]") Then
			WinActivate("[CLASS:NUIDialog]")
			Send("N")  
			Sleep(1000)
		EndIf
	EndIf
	
	While (ProcessExists("EXCEL.EXE"))
		WinActivate("[CLASS:XLMAIN]")
		Sleep(500)
		Send("!f")   ;Open "File" Menu.
		Sleep(500)
		Send("!f")   ;Open "File" Menu. For DOC type, after print, must sent !f twice. Word then can respond.
		Sleep(1000)
		Send("x")   ;Exit 
		Sleep(1000)
	WEnd
	
	#cs
	If ProcessExists("EXCEL.EXE") Then
		ProcessClose("EXCEL.EXE")
		Sleep(1000)
	EndIf
	#ce
	
	If ProcessExists("WINWORD.EXE") Then
		ProcessClose("WINWORD.EXE")
		Sleep(1000)
	EndIf
	
	If ProcessExists("POWERPNT.EXE") Then
		ProcessClose("POWERPNT.EXE")
		Sleep(1000)
	EndIf	
	#ce
EndFunc


;get AP index in Application Properties ListBox
Func GetApplicationPropertiesListBoxIconIndex($sIconName)
	Local $nIndex = ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, $sIconName)
	Return $nIndex
EndFunc

Func GetAppBarIconIndex($sIconName)
	For $i=1 To $nIconCount
		Local $sValue = ReadIniKeyValue($sPCodeIniPath, $sSectionAppBar, $i)
		If $sValue = $sIconName Then
			Return $i
		EndIf
	Next
	Return 0
EndFunc

Func GetAppBarPos($hPMHandle)
	Local $posAppBar = ControlGetPos($hPMHandle, "", $sApplicationBar)
	Return $posAppBar
EndFunc

Func QuitWordExcel()
	Common_SleepTime()
	Send("!f")
	Send("x")
	Common_SleepTime(3)
	If ProcessExists("WINWORD.exe") Then
		ProcessClose("WINWORD.exe")	
	EndIf
	If ProcessExists("EXCEL.exe") Then
		ProcessClose("EXCEL.exe")	
	EndIf
	Common_SleepTime()
EndFunc

Func OpenApplicationProperties()
	Common_SleepTime() 
	Send("!f")
	Send("u")
	Common_SleepTime() 
	Send("{enter}")
	Common_SleepTime() 
EndFunc

Func OpenSampleFolder($PMTitle)
	Common_SleepTime(2) 
	Local $hPM=WinGetHandle($PMTitle)
	Local $hTreeView=ControlGetHandle(WinGetHandle($PMTitle),"",$sTreeViewCtrInfo)
	ControlTreeView ($hPM, "",$sTreeViewCtrInfo,"Expand", "#0|#2")
	Common_SleepTime(1) 
	ControlTreeView ($hPM, "",$sTreeViewCtrInfo,"Expand", "#0|#2|#0")
	Common_SleepTime(1) 
	Local $hItemFound = _GUICtrlTreeView_FindItem($hTreeView,$sSectionAppBar)
	_GUICtrlTreeView_Expand($hTreeView, $hItemFound)
	Common_SleepTime(1)
	Local $hItemFound1 = _GUICtrlTreeView_FindItem($hTreeView, "Sample")
	_GUICtrlTreeView_ClickItem($hTreeView, $hItemFound1)
	Common_SleepTime(2) 
EndFunc	

Func SetAppShowInAppBar($sIconName,$bShow=1)
	Local $sAction = "Check"
	Common_SleepTime(2) 
	OpenApplicationProperties()
	Local $nIndex = GetApplicationPropertiesListBoxIconIndex($sIconName)
	Local $hAppListBoxHandle = ControlGetHandle($sApplicationPropertiesDialogTitle, "", $sAppListBox)
	_GUICtrlListBox_SetCurSel($hAppListBoxHandle,$nIndex)
	Common_SleepTime()
	If NOT $bShow Then
		$sAction = "UnCheck"
	EndIf
	Common_SleepTime(2)
	ControlCommand($sApplicationPropertiesDialogTitle,"",$sAppearInAppBarCheckBox,$sAction, "")  ;check on Appear in Application Bar
	ControlClick($sApplicationPropertiesDialogTitle,"",1)										;click the OK button
	Common_SleepTime() 
EndFunc

Func _ClickIconOnAppBar($sIconName, $Button)
	Switch $sIconName
	Case 'OUTLOOK'
		MouseClick($Button, 154, 989)
	Case 'PDFWRITER'	
		MouseClick($Button, 92,  989)
	Case 'WORDPAD'	
		MouseClick($Button, 400,  989)		
	Case 'PRINTFUN'	
		MouseClick($Button, 337,  989)		
	Case 'MSPAINT'	
		MouseClick($Button, 337,  989)	
	Case 'MSIE'	
		MouseClick($Button, 648,  989)		
	Case 'WORD'	
		MouseClick($Button, 524,  989)		
	Case 'PPT'	
		MouseClick($Button, 588,  989)			
	EndSwitch
EndFunc
Func ClickIconOnAppBar($sIconName,$Button,$posAppBar)
	Local $nIndex = GetAppBarIconIndex($sIconName)
	If NOT $nIndex Then
		Common_SleepTime(2) 
		SetAppShowInAppBar($sIconName)
		Common_SleepTime(2)
		If $nIconCount < $nMaxIconCount Then
			$nIndex = 	$nIconCount+1
		Else
			For $i = 0 To ($nIconCount-$nMaxIconCount) 
				MouseClick("left",$posAppBar[0]+$posAppBar[2]-$nIconWidth*2,$posAppBar[1]+$posAppBar[3]*0.7)
				Common_SleepTime() 
			Next
			$nIndex = $nMaxIconCount
		EndIf
	EndIf
	Common_SleepTime() 
	If $Button Then
		MouseClick($Button,$posAppBar[0]+$nIconWidth*($nIndex+1),$posAppBar[1]+$posAppBar[3]*0.7)
	EndIf
	Common_SleepTime(2) 
	Return $nIndex
EndFunc

Func CopySamppleToPMFolder()
	FileCopy($COMMON_SAMPLES_FOLDER_PATH & 'JPEG_Color.jpg', $PMFolder, 1)
	Sleep(500)
	Send('{F5}')
	Sleep(500)
EndFunc

Func CliclPDFWriterOnAPBAr($Btn)
	MouseClick($Btn,92, 987)
EndFunc
